import { getMyPeer, MyPeer } from '../../api/wxuser/index'
import config from '../../config/index'
import { getUserInfo } from '../../utils/storage'
Page({
  data: {
    user: {} as WxUser,
    myPeerList: [] as MyPeer[]
  },
  onLoad() {
    this.initData()
  },
  async initData() {
    const user = getUserInfo() as WxUser
    const res = await getMyPeer(user.id)
    if(res.statusCode === config.SUCCESS_CODE) {
      this.setData({
        myPeerList: res.data as MyPeer[]
      })
    }
    this.setData({
      user
    })
  },
  toDetail(e: any) {
    let id: string = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/peerCarDetail/peerCarDetail?id=${id}`
    })
  }
})